home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / birdstuf.zip / BIRDSTUF.PAS < prev   
Pascal/Delphi Source File  |  1990-07-21  |  3KB  |  85 lines

  1. {The following unit contains one function.  This function will initialize the
  2. Borland BGI interface in a Turbo Pascal program.  I wrote this unit in TP
  3. 5.5, but it should work for all versions of TP after 4.0.
  4.  
  5. The function performs two actions which I think can help graphics programs
  6. immensely.  The first is to obtain the path for the BGI (and CHR) drivers
  7. from an environmental variable BGIDIR.  The second action is to edit the
  8. driver and mode passed to the initialization unit against what is detected
  9. by TP.  The function returns a boolean to say if it was able to successfully
  10. initialize the driver.
  11.  
  12. I hope this helps someone.
  13. }
  14. Unit BirdStuf;
  15.  
  16. Interface
  17.  
  18. Uses
  19.     Dos,
  20.     Graph;
  21.  
  22. Const
  23.         Bird_DetectDriver = $0;
  24.         Bird_Highest_Mode = $255;
  25.  
  26.  
  27.     Function Init_Graphics (var GraphDriver, GraphMode : Integer) : Boolean;
  28.     {    This function will initialize the Turbo Graphics for the requested
  29.         graphics mode if and only if the requested mode is valid for the
  30.         machine the function is run in.  Another feature of this function is
  31.         that it will look for an environmental variable named 'BGIDIR'.  If
  32.         this variable is found, it will attempt to initialize the graphics
  33.         mode looking for the BGI driver using the string associated with BGIDIR
  34.         as the path.  If the correct BGI driver is not available, or if there is
  35.         not BGIDIR variable in the environment, it will attempt to initialize
  36.         using the current directory. }
  37.  
  38.  
  39. Implementation
  40.  
  41.     Function Init_Graphics (var GraphDriver, GraphMode : Integer) : Boolean;
  42.  
  43.  
  44.     const
  45.         ENV_BGI_PATH = 'BGIDIR';
  46.  
  47.     var
  48.         Dtect_Driver,
  49.         Dtect_Mode    : Integer;
  50.         BGI_Path    : String;
  51.  
  52.     Begin { Init_Graphics }
  53.  
  54.         { Default to not work }
  55.         Init_Graphics := False;
  56.  
  57.         DetectGraph(Dtect_Driver, Dtect_Mode);
  58.         If GraphDriver = Bird_DetectDriver then
  59.             GraphDriver := Dtect_Driver;
  60.         If Dtect_Driver = GraphDriver
  61.         Then Begin { Drivers match }
  62.             If GraphMode = Bird_Highest_Mode then
  63.                 GraphMode := Dtect_Mode;
  64.             If GraphMode <= Dtect_Mode
  65.             Then Begin { Mode OK }
  66.                 BGI_Path := GetEnv(ENV_BGI_PATH);
  67.                 InitGraph(GraphDriver,GraphMode,BGI_Path);
  68.                 if GraphResult = grOk
  69.                 then
  70.                     Init_Graphics := True
  71.                 Else Begin { Try current Directory }
  72.                     InitGraph(GraphDriver,GraphMode,'');
  73.                     if GraphResult = grOk then
  74.                         Init_Graphics := True;
  75.                 End; { Try current Directory }
  76.             End; { Mode OK }
  77.         End; { Drivers match }
  78.     End; { Function Init_Graphics }
  79.  
  80. Begin { Unit BirdStuf }
  81. End.
  82. {
  83. Mike Bird - B. Dalton, Bookseller                         bird@clavdivs.MN.ORG
  84. Helen Bird - Hummingbird Tailors                         helen@clavdivs.MN.ORG
  85. }